package pers.course.week5;

import java.util.Scanner;
import java.text.*;

public class AddTax {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cases = in.nextInt();
        for (int i = 0; i < cases; i++) {
            String good = in.next();
            int price = in.nextInt();
            int num = in.nextInt();
            String[] goods = new String[num];
            for (int j = 0; j < num; j++) {
                goods[j] = in.next();
            }
            if (func(good, goods)) {
                double result = price * 1.1;
                DecimalFormat df = new DecimalFormat("#0.00");
                System.out.println(df.format(result));
            } else {
                double result = price * 1.18;
                DecimalFormat df = new DecimalFormat("#0.00");
                System.out.println(df.format(result));
            }
        }
    }
    public static boolean func(String good, String[] goods) {
        for (String s : goods) {
            if (good.equals(s)) {
                return true;
            }
        }
        return false;
    }
}
